Open
Conversation
Implement GL_SCISSOR_TEST at the RenderTarget level to support
arbitrary clipping of rendered areas, and implement translation
functions to support scrolling of arbitrary rendered areas. These
primarily support the implementation of nested GUI elements that
can be visibly clipped within and scrollable by a parent container.
- Add scissor_stack vector, push/popScissorRect() to define and
access visible areas defined as sp::Rects.
- Add translation_stack vector, push/popTranslation() to define and
access positional deltas, translate them to pixel coordinates,
and track the render's total translation value.
- Add getTranslation() to expose the total current translation
value, to allow for relative positioning to a translated render.
- Add static applyProjectionMatrix() to apply a translation to a
2D projection matrix, for mapping a virtual coordinate to a
relative screen position.
This allows the definition of a GUI container that renders and
interacts with only what is within a scissor rect, while allowing
overflow content to be scrolled (translated) into that rect.
For example, given:
void GuiScrollContainer::drawElements(
glm::vec2 mouse_position,
sp::Rect /* parent_rect */,
sp::RenderTarget& renderer
)
{
sp::Rect content_rect = getContentRect();
renderer.pushScissorRect(content_rect);
renderer.pushTranslation({0.0f, -scroll_offset});
glm::vec2 layout_mouse = mouse_position + glm::vec2{
0.0f, scroll_offset
};
for (auto it = children.begin(); it != children.end(); )
{
... pass translated mouse events through to scrolled
contents ...
}
renderer.popTranslation();
renderer.popScissorRect();
}
Rendering of all child elements of this container is clipped to
the parent's content_rect dimensions and shifted vertically by the
translation offset. Mouse events are also passed through to the
translated positions of the child elements.
This was referenced Mar 9, 2026
daid
reviewed
Mar 19, 2026
daid
reviewed
Mar 19, 2026
src/graphics/renderTarget.h
Outdated
|
|
||
| // Stack nested translation vectors to determine their offsets relative to | ||
| // the container and each other. | ||
| void pushTranslation(glm::vec2 virtual_offset); |
Owner
There was a problem hiding this comment.
Not sure if I like these. Feels like a recipe for confusion in combination with the layout managers of the GUI system.
Contributor
Author
There was a problem hiding this comment.
Removed them and implemented scroll_offset in GuiContainer/GuiScrollContainer to be applied in updateLayout(). So clipping remains part of RenderTarget and scrolling is now part of the layout system.
Make this the game's layout system's responsibility instead.
d5dd0b8 to
c121e94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement
GL_SCISSOR_TESTat theRenderTargetlevel to support arbitrary clipping of rendered areas. Addclip_region_stackvector,push/popClipRegion()to define and access visible areas as intersectedsp::Rects.These primarily support the implementation of nested GUI elements that can be visibly clipped within and scrolled by a parent container.
This allows the definition of a GUI container that renders and interacts with only what is within a clip region, while allowing overflow content to be scrolled by repositioning other elements into the clip region.
For example, given:
Rendering of all child elements of this container is clipped to the parent's
content_rectdimensions and shifted vertically by thescroll_offsetvia overriddenGuiContainer::updateLayout(). Mouse events (clicks, hover, focus changes) are also passed through to the repositioned child elements.